﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AlarmClock.UI.Controls
{
    public partial class Combox_Ctrl : ComboBox
    {
        public enum InputStyle
        {
            OnlyDigit = 0,
            OnlyLetter = 1,
            Both = 2,
        }

        InputStyle inputstyle = InputStyle.Both;

        [Description("可以设置为 0：仅数字输入； 1：仅字母输入  2：支持所有输入")]
        public InputStyle inputstyle_State
        {
            get { return inputstyle; }
            set{ inputstyle = value;this.Invalidate(); }
        }

        public Combox_Ctrl()
        {
            InitializeComponent();

            this.Size = new Size(76, 35);
            this.BackColor = Color.FromKnownColor(KnownColor.Window);
            this.ItemHeight = 27;
            this.MaxLength = 2;
            this.Text = "00";
            this.FormatString = "N0";
            this.DropDownStyle = ComboBoxStyle.DropDown;

            this.KeyPress += new KeyPressEventHandler(Cbo_KeyPress);
        }

        private void Cbo_KeyPress(object sender, KeyPressEventArgs e)
        {
            if(inputstyle==InputStyle.OnlyDigit)
                e.Handled = !char.IsDigit(e.KeyChar);//不是数字就是true了，会直接返回
        }
    }
}
